package com.teng.web.servlet;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.teng.dto.JSONResponse;
import com.teng.dto.UserContext;
import com.teng.entity.RecycleEntity;
import com.teng.exception.OAException;
import com.teng.service.RecycleService;
import com.teng.service.impl.RecycleServiceImpl;
import com.teng.util.JSONUtil;
@WebServlet("/api/document/rec/list")
public class RecycleListServlet extends HttpServlet{
		@Override
		protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			JSONResponse result=new JSONResponse();
			try {
			req.setCharacterEncoding("utf-8");
			String key=req.getParameter("key");
			HttpSession session=req.getSession();
			UserContext uc=(UserContext)session.getAttribute("LOGIN");
			RecycleService rcs=new RecycleServiceImpl();
			List<RecycleEntity> re=rcs.recyclelist(uc.getId());
			result.setCode("ok");
			result.setData(re);
			}catch(OAException e) {
				result.setCode("error");
				result.setMessage(e.getMessage());
			}catch(Exception e) {
				result.setCode("error");
				result.setMessage("系统错误！请稍后再试");
				e.printStackTrace();
			}finally {
				resp.setCharacterEncoding("utf-8");
				resp.setContentType("application/json");
				Writer out=resp.getWriter();
				out.write(JSONUtil.toJsonString(result));
			}
		}
}
